﻿/*
* 创建人:            @Model.Author
* 创建时间:          @Model.CreateTime
* 邮箱：             @Model.EmailAddress
* 文件功能描述：      @Model.FileRemark
*
* 修改人：
* 时间：
* 修改说明：
*/
@{
    Layout = null;
}
@model SJNScaffolding.Models.TemplateModels.ViewFileModel
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Linq.Extensions;
using @(Model.ProjectName).Domain.Plat.@(Model.TableName)s.Dto;
using @(Model.ProjectName).Usual;

namespace @(Model.ProjectName).Domain.Plat.@(Model.TableName)s
{
    public class @(Model.TableName)AppService : UsualCrudAppService<@(Model.TableName+",")@(Model.TableName)ListDto, @(Model.TableName)SearchDto, @(Model.TableName)InputDto, @Model.IdType>, I@(Model.TableName)AppService
    {
        private readonly IRepository<@(Model.TableName+",")@(Model.IdType)>_@(Model.TableNameCamel)Repository;

        public @(Model.TableName)AppService(IRepository<@(Model.TableName+","+Model.IdType)>@(Model.TableNameCamel)Repository) : base(@(Model.TableNameCamel)Repository)
        {
            _@(Model.TableNameCamel)Repository = @(Model.TableNameCamel)Repository;
            @if(Model.HasPermission){
                @Html.Raw("          base.GetPermissionName =\"Plat."+Model.TableName+"\";\r\n");
                @Html.Raw("          base.GetAllPermissionName = \"Plat." + Model.TableName + ".GetGrid\";\r\n");
                @Html.Raw("          base.CreatePermissionName = \"Plat."+Model.TableName+".Add\";\r\n");
                @Html.Raw("          base.UpdatePermissionName = \"Plat."+Model.TableName+".Edit\";\r\n");
                @Html.Raw("          base.DeletePermissionName = \"Plat."+Model.TableName+".Delete\";\r\n");
            }
        }

        protected override IQueryable<@(Model.TableName)> CreateFilteredQuery(@(Model.TableName)SearchDto input)
        {
         @if(Model.SearchColumnNames!=null)
         {
             string tempRaw="return base.CreateFilteredQuery(input)";
             foreach(var item in Model.SearchColumnNames)
             {
                 switch (item.AttrType)
                 {
                    case "string":
                        tempRaw+=$"\r\n             .WhereIf(input.{item.ColumnName}.IsNotNullOrWhiteSpace(),u=>u.{item.ColumnName}.Contains(input.{item.ColumnName}))";
                        break;
                     case "int":
                         tempRaw+=$"\r\n                .WhereIf(input.{item.ColumnName}!=0,u=>u.{item.ColumnName}=={item.ColumnName})";
                         break;
                     case "int?":
                         tempRaw+=$"\r\n                .WhereIf(input.{item.ColumnName}!=0&&input.{item.ColumnName}!=null,u=>u.{item.ColumnName}=={item.ColumnName})";
                         break;
                    default:break;
                 }
             }
             tempRaw += ";\r\n";
             @Html.Raw("                "+tempRaw);
         }
         else{
            @("return base.CreateFilteredQuery(input);")
         }
        }
    }
}
